package com.liuyucheng.idea_springboot.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

/**
 * 说明
 *
 * @author LiuYuCheng
 * @date 2023年06月30日 10:13
 */
//让spring知道这是一个切面类
@Aspect
public class Linux {


    //切入点 *表示任何方法 ..表示所有参数
    @Pointcut("execution(public int com.liuyucheng.idea_springboot.aop.Sp.*(..))")
    public void pointcut() {

    }

    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        //方法名称
        String methodName = joinPoint.getSignature().getName();
        //参数
        Object[] args = joinPoint.getArgs();
        System.out.println(methodName + "方法，前置通知:,参数:" + Arrays.asList(args));
    }


    @After("pointcut()")
    public void after(JoinPoint joinPoint) {
        //方法名称
        String methodName = joinPoint.getSignature().getName();
        //参数
        Object[] args = joinPoint.getArgs();
        System.out.println(methodName + "方法，后置通知:,参数:" + Arrays.asList(args));
    }

    @AfterReturning(value = "pointcut()", returning = "result")
    public void afterReturning(JoinPoint joinPoint, Object result) {
        //方法名称
        String methodName = joinPoint.getSignature().getName();
        //参数
        Object[] args = joinPoint.getArgs();
        System.out.println(methodName + "方法，返回通知:,参数:" + Arrays.asList(args) + ",结果:" + result);
    }

    @AfterThrowing(value = "pointcut()", throwing = "e")
    public void afterThrowing(JoinPoint joinPoint, Exception e) {
        //方法名称
        String methodName = joinPoint.getSignature().getName();
        //参数
        Object[] args = joinPoint.getArgs();
        System.out.println(methodName + "方法，异常通知:,参数:" + Arrays.asList(args) + ",异常信息:" + e);
    }
}